from fuzzywuzzy import fuzz
import time

a="ystmslq"
b="ystmsqs"


start_time = time.time()

for i in range(10000):
    similarity = fuzz.ratio(a.lower(), b.lower())


print("fuzz.ratio:",similarity)

end_time = time.time()
elapsed_time = end_time - start_time
print("经过的时间：", elapsed_time, "秒")


start_time = time.time()

def levenshtein_distance(a, b):
    m = len(a)
    n = len(b)

    # 创建一个二维数组来存储编辑距离
    dp = [[0] * (n + 1) for _ in range(m + 1)]

    # 初始化第一行和第一列
    for i in range(m + 1):
        dp[i][0] = i
    for j in range(n + 1):
        dp[0][j] = j

    # 动态规划计算编辑距离
    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if a[i - 1] == b[j - 1]:
                dp[i][j] = dp[i - 1][j - 1]
            else:
                dp[i][j] = min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]) + 1

    return dp[m][n]

for i in range(10000):
    distance = levenshtein_distance(a, b)

#逻辑非常简单，(1-修改的次数/两个句子的总字数（不去重）)*100
print("手搓：",int(round((1-distance/(len(a)+len(b)))*100,0)))

end_time = time.time()
elapsed_time = end_time - start_time
print("经过的时间：", elapsed_time, "秒")